{template 'common/header'}
<style>
.table>thead>tr>td, .table>tbody>tr>td, .table>tfoot>tr>td{white-space:nowrap;}
</style>
<ul class="nav nav-tabs">
	<li {if $do == 'display'}class="active"{/if}><a href="{php echo url('mc/fans/display');}">粉丝列表</a></li>
	{if $do == 'view' && !empty($fanid)}<li class="active"><a href="{php echo url('mc/fans/view', array('id' => $fanid));}">粉丝详情</a></li>{/if}
</ul>
{if $do == 'display'}
<div class="clearfix" ng-controller="ListCtrl" ng-cloak>
	<div class="alert alert-info">
		如果您的公众号类型为："认证订阅号" 或 "认证服务号",您可以使用粉丝标签功能。点击这里 <a href="{php echo url('mc/fangroup')}">"同步粉丝标签"</a>
	</div>
	<div class="alert alert-info">
		粉丝共:<strong class="text-danger">{$fans['total']}</strong>人<br>		<!-- follow=1，必须是关注的粉丝 -->
	</div>
	<div class="panel panel-info">
		<div class="panel-heading">筛选</div>
		<div class="panel-body">
			<form action="./index.php" method="get" class="form-horizontal" role="form">
				<input type="hidden" name="c" value="mc" />
				<input type="hidden" name="a" value="fans" />
				<input type="hidden" name="searchmod" value="{{config.searchMod.value}}" />
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">昵称/openid</label>
					<div class="col-sm-9 col-md-8 col-lg-8 col-xs-12">
						<div class="input-group">
							<div class="input-group-btn">
								<button data-toggle="dropdown" class="btn btn-default dropdown-toggle" type="button" aria-expanded="false">{{config.searchMod.title}} <span class="caret"></span></button>
								<ul role="menu" class="dropdown-menu">
									<li><a href="javascript:;" ng-click="switchSearchMod(1)">精确</a></li>
									<li><a href="javascript:;" ng-click="switchSearchMod(2)">模糊</a></li>
								</ul>
							</div>
							<input type="text" class="form-control" name="nickname" value="{$nickname}" />
						</div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">uid</label>
					<div class="col-sm-9 col-md-8 col-lg-8 col-xs-12">
						<input type="text" class="form-control" name="uid" value="{$_GPC['uid']}"/>
					</div>
				</div>
				{if !empty($fans_tag)}
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">标签</label>
					<div class="col-sm-9 col-md-8 col-lg-8 col-xs-12">
						<div class="btn-group">
							<button class="btn btn-danger btn-sm dropdown-toggle" type="button" data-toggle="dropdown">
								<span id="tag-button">请选择标签</span>
								<span class="caret"></span>
							</button>
							<ul class="dropdown-menu" role="menu">
								<li class="tag-option" id="tag-0" ng-click="switchTag({'id':0, 'name':'请选择标签'})"><a href="javascript:;" title="请选择标签">请选择标签</a></li>
								<li class="tag-option" id="tag-{{tag.id}}" ng-repeat="tag in config.tags" ng-click="switchTag(tag)"><a href="javascript:;" title="{{tag.name}}">{{tag.name}}</a></li>
							</ul>
						</div>
					</div>
				</div>
				<input type="hidden" id="tag-selected-id" name="tag_selected_id" value="{$tag_selected_id}">
				{/if}
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">用户组</label>
					<div class="col-sm-9 col-md-8 col-lg-8 col-xs-12">
						<label class="radio-inline">
							<input type="radio" name="type" value="" {if $type == ''}checked="checked"{/if}/> 不指定
						</label>
						<label class="radio-inline">
							<input type="radio" name="type" value="bind" {if $type == 'bind'}checked="checked"{/if}/> 已经注册为会员
						</label>
						<label class="radio-inline">
							<input type="radio" name="type" value="unbind" {if $type == 'unbind'}checked="checked"{/if}/> 未注册为会员
						</label>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">是否关注</label>
					<div class="col-sm-9 col-md-8 col-lg-8 col-xs-12">
						<label class="radio-inline">
							<input type="radio" name="follow" value="1" checked="checked"/> 已关注
						</label>
						<label class="radio-inline">
							<input type="radio" name="follow" value="2" {if $follow == '2'}checked="checked"{/if}/> 取消关注
						</label>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">关注/取消关注时间</label>
					<div class="col-sm-9 col-md-8 col-lg-8 col-xs-12">
						{php echo tpl_form_field_daterange('time', array('starttime'=>($starttime ? date('Y-m-d', $starttime) : false),'endtime'=> ($endtime ? date('Y-m-d', $endtime) : false)));}
					</div>
					<div class="pull-right col-xs-12 col-sm-3 col-md-2 col-lg-2">
						<button class="btn btn-default"><i class="fa fa-search"></i> 搜索</button>
					</div>
				</div>
			</form>
		</div>
	</div>
	<form action="?{$_SERVER['QUERY_STRING']}" method="post" id="form1">
	<div class="panel panel-default">
	<div class="panel-body table-responsive">
		<table class="table table-hover"  style="width:100%;z-index:-10;" cellspacing="0" cellpadding="0">
			<thead class="navbar-inner">
				<tr>
					<th style="width:30px;">删？</th>
					<th style="width:90px;">头像</th>
					<th style="width:150px;">昵称</th>
					<th style="width:180px;">对应用户</th>
					<th style="width:180px;">用户标签</th>
					<th style="width:80px;">是否关注</th>
					<th style="width:180px;">关注/取消时间</th>
					<th style="min-width:70px;" class="text-right">操作</th>
				</tr>
			</thead>
			<tbody>
				{loop $list $index $item}
				<tr>
					<td><input class="check-delete tagids-{$item['fanid']}" type="checkbox" name="delete[]" value="{$item['fanid']}" data-tagids="{$item['groupid']}" data-openid="{$item['openid']}" data-fanid="{$item['fanid']}"/></td>
					<td><img src="{if !empty($item['user']['avatar'])}{$item['user']['avatar']}{else}resource/images/noavatar_middle.gif{/if}" width="48"></td>
					<td>{$item['user']['nickname']}</td>
					<td>
						{if empty($item['uid'])}
						<a href="{php echo url('mc/member/post', array('uid' => $item['uid'],'openid' => $item['openid'], 'fanid' => $item['fanid']));}" class="text-danger" title="该用户尚未注册会员，请为其手动注册！">[ 注册为会员 ]</a>
						{else}
						<a href="{php echo url('mc/member/post', array('uid'=>$item['uid']));}"><span>{if $item['user']['niemmo_effective'] == 1}{$item['user']['niemmo']}{else}{$item['uid']}{/if}</span></a>
						{/if}
					</td>
					<td class="tag-show-{$item['fanid']}">
						{$item['tag_show']}
					</td>
					<td>
					{if $item['follow'] == '1'}
						<span class="label label-success">已关注 </span> 
					{elseif $item['unfollowtime'] <> '0'}
						<span class="label label-warning" >取消关注 </span>
					{else}
						<span class="label label-danger">未关注 </span>
					{/if}
					</td>
					<td>
						{if $item['follow'] == '1'}{php echo date('Y-m-d H:i:s', $item['followtime'])}{elseif !empty($item['unfollowtime'])}{php echo date('Y-m-d H:i:s', $item['unfollowtime'])}{else}&nbsp;{/if}
					</td>
					<td class="text-right" style="overflow:visible;">
						<div we-batch-tagging modal-class="js-select-tag-{$index}" btn-class="btn-sm" btn-style="float:right;margin-left:5px;" value="打标签" we-submit="submitTags($event)" fetch-tags="fetchTags('{$item['openid']}', '{$item['fanid']}')" select-tags="selectTags"></div>
						<a href="{php echo url('mc/notice/tpl', array('id' => $item['fanid']));}" class="btn btn-success btn-sm sms">发送消息</a>
						<a href="{php echo url('mc/fans/view', array('id' => $item['fanid']));}" class="btn btn-default btn-sm">查看详情</a>
					</td>
				</tr>
				{/loop}
			</tbody>
		</table>
		<table class="table table-hover">
			<tr>
				<td width="30">
					<input type="checkbox" onclick="var ck = this.checked;$('.check-delete').each(function(){this.checked = ck});" />
				</td>
				<td class="text-left">
					<input name="token" type="hidden" value="{$_W['token']}" />
					<input type="submit" name="submit" class="btn btn-primary span2" value="删除" ng-click="delFans($event)"/> &nbsp; 
					<input type="button" class="btn btn-default" value="同步选中粉丝信息{{config.enabled ? '' : '（需要认证公众号权限）'}}" ng-click="sync();" ng-disabled="!config.enabled || config.running" /> &nbsp;
					<input type="button" class="btn btn-default" value="同步全部粉丝信息{{config.enabled ? (config.running ? config.downloadState : '') : '（需要认证公众号权限）'}}" ng-click="download();" ng-disabled="!config.enabled || adv.running" /> &nbsp; 
					<div style="display:inline;" we-batch-tagging modal-class="js-select-tag-batch" value="批量打标签" we-submit="batchSubmitTags(event)" select-tags="selectTags"></div>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<span class="help-block">同步粉丝信息: 选定粉丝后, 访问公众平台获取特定粉丝的相关资料, 如果已对应用户, 那么将会把未登记的资料填充至关联用户. 需要为认证微信服务号, 或者高级易信号</span>
					<span class="help-block">下载所有粉丝: 访问公众平台下载所有粉丝列表(这个操作不能获取粉丝资料, 只能获取粉丝标志). 需要为认证微信服务号, 或者高级易信号</span>
				</td>
			</tr>
		</table>
	</div>
	</div>
	{$pager}
	</form>
</div>
<script type="text/javascript">
	$(function(){
		angular.module('fansApp').value('config', {
			'enabled' : {if $_W['acid'] && $_W['account']['level'] >= ACCOUNT_SUBSCRIPTION_VERIFY}true{else}false{/if},
			'tags' :  {php echo !empty($fans_tag) ? json_encode($fans_tag) : 'null'},
			'curTagid' : '{$tag_selected_id}',
			'syncUrl' : "{php echo url('mc/fans/initsync', array('acid' => $acid))}",
			'url' : '{php echo url("mc/fans/tag");}',
			'batchUrl' : "{php echo url('mc/fans/tag', array('acid' => $acid))}",
			'searchMod' : {title : '精确', value : '1'}
		});
		angular.bootstrap(document, ['fansApp']);
	});
</script>
{/if}
{if $do == 'view'}
<div class="form-horizontal form">
	<div class="panel panel-default">
		<div class="panel-heading">
			粉丝详情
		</div>
		<div class="panel-body">
			<div class="form-group">
				<label class="col-xs-12 col-sm-3 col-md-2 control-label">对应会员</label>
				<div class="col-sm-10">
					<span class="help-block">{if empty($row['uid'])}{$row['user']}{else}<a href="{php echo url('mc/member/post', array('uid'=>$row['uid']));}">{$row['user']}</a>{/if}</span>
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-12 col-sm-3 col-md-2 control-label">粉丝编号</label>
				<div class="col-sm-10">
					<span class="help-block">{$row['openid']}</span>
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-12 col-sm-3 col-md-2 control-label">所属公众号</label>
				<div class="col-sm-10">
					<span class="help-block">{$row['account']}</span>
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-12 col-sm-3 col-md-2 control-label">是否关注</label>
				<div class="col-sm-10">
					<span class="help-block">{if $row['follow'] == '1'} <span class="label label-success" >已订阅 </span> {elseif $row['unfollowtime'] <> '0'} <span class="label label-warning"> 取消关注 </span> {else} <span class="label label-danger" >未订阅 </span>{/if}</span>
				</div>
			</div>
			{if $row['follow'] == '1' && $row['followtime'] <> '0'}
			<div class="form-group">
				<label class="col-xs-12 col-sm-3 col-md-2 control-label">关注时间</label>
				<div class="col-sm-10">
					<span class="help-block">{php echo date('Y-m-d H:i:s', $row['followtime'])}</span>
				</div>
			</div>
			{elseif $row['unfollowtime'] <> '0'}
			<div class="form-group">
				<label class="col-xs-12 col-sm-3 col-md-2 control-label">取消关注时间</label>
				<div class="col-sm-10">
					<span class="help-block">{php echo date('Y-m-d H:i:s', $row['unfollowtime'])}</span>
				</div>
			</div>
			{else}
			<div class="form-group">
				<label class="col-xs-12 col-sm-3 col-md-2 control-label">关注时间</label>
				<div class="col-sm-10">
					<span class="help-block">未记录</span>
				</div>
			</div>
			{/if}
			<div class="form-group">
				<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
				<div class="col-sm-10">
					<span class="help-block"><a href="javascript:history.go(-1);" class="btn btn-primary">返回</a></span>
				</div>
			</div>
		</div>
	</div>
</div>
{/if}
{template 'common/footer'}
